-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add step by step nav GA4 tracking #3052
Conversation
app/assets/javascripts/govuk_publishing_components/components/step-by-step-nav.js
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, would definitely echo the comment that this needs some tests. I think a rb
test to check the right attributes are applied in the right places, and a js
test to check that the right things happen with the addition of attributes to the show/hide all button.
app/views/govuk_publishing_components/components/_step_by_step_nav.html.erb
Outdated
Show resolved
Hide resolved
app/views/govuk_publishing_components/components/docs/step_by_step_nav.yml
Show resolved
Hide resolved
d36537a
to
c44ff1a
Compare
c44ff1a
to
bf3c85c
Compare
Thanks @andysellick @JamesCGDS - I've added a JS test and a Ruby test. I'll squash the commits once everything is approved. @andysellick we don't have ruby tests on the accordions/tabs/header etc. If we're adding a ruby test here, we should add them on the other components too in my opinion. |
@@ -4,9 +4,9 @@ | |||
describe('A stepnav module', function () { | |||
'use strict' | |||
|
|||
var $element | |||
var $element, element |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm using element
here as I'm not using jQuery like the other tests, and variables starting with $
indicate they're a jQuery variable, so I didn't use it.
bf3c85c
to
eeb35e4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 👍 Would it be possible to hold off on merging this until #3057 has been merged?
app/assets/javascripts/govuk_publishing_components/components/step-by-step-nav.js
Outdated
Show resolved
Hide resolved
eeb35e4
to
cfbdf25
Compare
cfbdf25
to
9916830
Compare
9916830
to
a0cef1f
Compare
a0cef1f
to
b8bd81b
Compare
b8bd81b
to
a24ccd2
Compare
a24ccd2
to
dc70c88
Compare
dc70c88
to
a9b02f3
Compare
a9b02f3
to
e13d7d6
Compare
e13d7d6
to
4edff50
Compare
4edff50
to
421c44f
Compare
421c44f
to
345e6d0
Compare
Hi @andysellick - the implementation has changed since James reviewed this. Due to the outcomes of our accordion refactor, I've refactored this implementation. Now the GTM JSON for everything is created using JavaScript. There was no use in hardcoding them onto the I haven't shared the function which adds the GTM JSON to the steps which is similar to the accordion function. (See line 86 in Would you be able to review the code? Thanks 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, just a few nitpicks but nothing serious.
app/assets/javascripts/govuk_publishing_components/components/step-by-step-nav.js
Outdated
Show resolved
Hide resolved
app/assets/javascripts/govuk_publishing_components/components/step-by-step-nav.js
Outdated
Show resolved
Hide resolved
345e6d0
to
f29daf1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, a couple more nitpicks. But otherwise good 👍
} | ||
} | ||
|
||
var ga4Data = this.$module.isGa4Enabled ? "data-ga4-event='" + JSON.stringify(ga4JSON) + "'" : '' // Construct GA4 data-attributes for ga4-event-tracker. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick - I'd be tempted to move this line inside the if
statement above for clarity i.e.
var ga4Data = ''
// Construct GA4 data-attributes for ga4-event-tracker
if (this.$module.isGa4Enabled) {
var ga4JSON = {
event_name: 'select_content',
type: 'step by step',
text: titleText.trim(),
index: i + 1,
index_total: this.$module.totalSteps
}
ga4Data = "data-ga4-event='" + JSON.stringify(ga4JSON) + "'" : ''
}
// if GA4 is enabled, set attributes on 'show all sections' for tracking using ga4-event-tracker | ||
if (this.$module.isGa4Enabled) { | ||
var indexTotal = this.$module.totalSteps | ||
var showAllAttributesGa4 = { event_name: 'select_content', type: 'step by step', index: 0, index_total: indexTotal } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick - might as well put this.$module.totalSteps
directly into the object rather than declaring it separately.
Enables GA4 tracking with the presence of 'ga4_tracking: true' on the component. ga4-event-tracker and data-ga4-expandable are then added to the template. We are then using JS to add all the GA4 JSONS. There is no use putting them on the HTML template, as the HTML gets reconstructed by JavaScript anyway in order to create the buttons.
f29daf1
to
58276d3
Compare
Hi @andysellick & @JamesCGDS - would you be able to approve this if everything is OK?
Thanks 👍
What
type: step by step
instead.ga4_tracking: true
when the component is rendered on a page.ga4_tracking: true
exists, it addsdata-module="ga4-event-tracker" data-ga4-expandable
. When this module is initialised, any child element that hasdata-ga4-event
on it gets tracked on click. Therefore we adddata-ga4-event
where needed, which holds the JSON data we want to send to GTM on click.data-ga4-expandable
is also added as this signals thega4-event-tracker
to track the value ofaria-expanded
and add it to the GTM object as 'opened'/'closed'.ga4-event-tracker
module, and populates the GTM JSONs for the 'Show all steps' button, and all the step buttons.Why
type: "step by step"
instead.Visual Changes
None.